/**
 * 测试/dev/zero对非血缘关系的进程是否支持；
 * @author: sundx
 * @date: 2020-05-22 17:13:25
 * @Last Modified by: sundx
 * @Last Modified time: 2020-05-30 22:04:09
 */
#include <fcntl.h>
#include <iostream>
#include <sys/mman.h>
#include <unistd.h>
void outError(const char *);
int main() {
  int *p;
  int fd = open("/dev/zero", O_RDWR);
  if (fd == -1)
    outError("open zero failed");
  p = (int *)mmap(NULL, 20, PROT_READ, MAP_SHARED, fd, 0);
  close(fd);
  while (1) {
    std::cout << *p << std::endl;
    sleep(1);
  }
  std::cout << "write ok" << std::endl;
  munmap(p, 20);
  return 0;
}
void outError(const char *errorMessage) {
  std::cout << errorMessage << std::endl;
  exit(EXIT_FAILURE);
}